﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq.Mapping;
using System.Data.Linq;


namespace PhotoGallery.Entities
{
    [Table]
    public class Photo
    {
        private int? _PhotoId;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
        public int? PhotoId {
            get {return _PhotoId;}
            set {this._PhotoId = value;}
        }

        
        [Column]
        public int CategoryId { get; set; }
        [Column]
        public DateTime UploadDate { get; set; }
        [Column]
        public String Name { get; set; }
        [Column]
        public int RatingCount { get; set; }
        [Column]
        public int RatingSumm { get; set; }
        [Column]
        public String PhotoInfo { get; set; }
        [Column]
        public Boolean IsIllegal { get; set; }


        private EntityRef<Image> _Image;//добавляем связь с таблицей изображений
        [Association(Name = "FK_Image_Photo", Storage = "_Image", ThisKey = "PhotoId")]
        public Image Image
        {
            get { return this._Image.Entity; }
            set { this._Image.Entity = value; }
        }


        public double GetRate()// расчет рейтинга фотки по ее id
        {
            double rezult = 0.0;
            rezult = RatingSumm / RatingCount;
            return rezult;
        }

        /*  private EntitySet<Tag> _Tag;//добавляем связь с таблицей тегов
        [Association(Name = "FK_Tag_Photo", Storage = "_Tag", ThisKey = "PhotoId")]
        public Tag Tag
        {
            get { return this._Tag.Entity; }
            set { this._Tag.Entity = value; }
        }
        */
 
    }
}